//
//  CZNewFeatureCell.swift
//  weibo27
//
//  Created by mac on 16/4/18.
//  Copyright © 2016年 it.cast. All rights reserved.
//

import UIKit

class CZNewFeatureCell: UICollectionViewCell {
    
    private lazy var iconImage:UIImageView = UIImageView()
    
    private lazy var startBtn:UIButton = UIButton(title: "开始体验", color: UIColor.redColor(), imageName: "new_feature_finish_button")
    //显示图像
    var imageIndex:Int = 0 {
        
        didSet{
            startBtn.hidden = true
            iconImage.image = UIImage(named: "new_feature_\(imageIndex+1)" )
            
        }
    }
    
    //添加按钮动画
    func startAnimation(){
        startBtn.hidden = false
        startBtn.userInteractionEnabled = false
        startBtn.transform = CGAffineTransformMakeScale(0, 0)
        
        UIView.animateWithDuration(2.0, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 8, options: [], animations: { () -> Void in
            
            //回到初始值的大小
               self.startBtn.transform = CGAffineTransformIdentity
            }) { (_) -> Void in
                self.startBtn.userInteractionEnabled = true
//                print("图像出现")
        }
    }
    
    //frame的大小是layout的大小
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        
        addSubview(iconImage)
        addSubview(startBtn)
        
        iconImage.frame = bounds
        
        startBtn.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(self.snp_centerX)
            //底部的约束
            make.bottom.equalTo(self.snp_bottom).multipliedBy(0.7)
            
            
            startBtn.addTarget(self, action: "startBtnClick", forControlEvents: .TouchUpInside)
        }
    }
    
    @objc private func startBtnClick(){
        
        //点击之后发送一个通知 
        NSNotificationCenter.defaultCenter().postNotificationName(WBSwitchRootViewControllerNotification, object: nil)
    }
}











